package utils

var CACHE_PREFIX = "cache:"

func SetString(key string, data string) error {
	Rds.Set(CACHE_PREFIX+key, data)
	return nil
}

func SetCache(key string, data any) error {
	dataStr := StructToJson(data)
	err := Rds.Set(CACHE_PREFIX+key, dataStr)
	if err != nil {
		return err
	}
	return nil
}

func GetString(key string) (string, error) {
	data, err := Rds.Get(CACHE_PREFIX + key)
	if err != nil {
		return "", err
	}
	return data, nil
}

func GetCache(key string, data any) error {
	dataStr, err := Rds.Get(CACHE_PREFIX + key)
	if err != nil {
		return err
	}
	err = JsonToStruct(dataStr, &data)
	if err != nil {
		return err
	}
	return nil
}
